package com.jy.api.util;

import com.aliyun.mns.client.CloudQueue;
import com.aliyun.mns.client.MNSClient;
import com.aliyun.mns.model.Message;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * Created by lihu on 2018/1/2.
 */
@Slf4j
@Data
@Component
public class AliyunMNSSend {


    @Autowired
    MNSClient client;

    @Value("${mns.cloud-queue}")
    private String cloudQueue;


    /**
     * mns 消息发送
     *
     * @param payId
     */
    public void sendClint(String payId) {
        CloudQueue queue = client.getQueueRef(cloudQueue);
        Message message = new Message();
        message.setMessageBody(payId);
        message.setPriority(8);
        Message putMsg = queue.putMessage(message);
        log.info("Send message id is:{}", putMsg.getMessageId());
    }

    /**
     * mns 消息发送
     *
     * @param orderId
     */
    public void sendPayClint(String orderId) {
        CloudQueue queue = client.getQueueRef(cloudQueue);
        Message message = new Message();
        message.setMessageBody("refund:" +orderId);
        message.setPriority(9);
        Message putMsg = queue.putMessage(message);
        log.info("Send message id is:{}", putMsg.getMessageId());
        log.info("orderId is:{}",orderId);
    }


}
